<script>
import { commonloginwxLogin, feastordergetUnPay,flag2coupon } from './untils/api.js';
let flag;
export default {
	async onLaunch(ops) {
		// console.log(ops.query);
		// let a = '';
		// if (ops.query.pid) {
		// 	a = ops.query.pid;
		// 	console.log(a);
		// }
		// if (ops.query.scene) {
		// 	a = decodeURIComponent(ops.query.scene);
		// 	a = a.split('=')[1];
		// 	console.log(a);
		// }
        console.log(ops);
        if(ops.query.scene){
            let scene = decodeURIComponent(ops.query.scene);
            flag = scene.replace(/flag=/g,'');
            uni.setStorageSync('flag',flag)
        } else{
            uni.setStorageSync('flag','')
        }
        console.log(ops)
		if (!uni.getStorageSync('token')) {
			this.login();
		} else{
		    if(flag){
                this.flag2couponFun(flag)
            }
        }
	},
	onLoad(ops) {
		console.log('ops首页', ops);
	},
	methods: {
        flag2couponFun(flag){
            flag2coupon({
                flag:flag
            }).then(res => {

            })
        },
		login1() {
			return new Promise((req, rej) => {
				uni.login({
					provider: 'weixin',
					onlyAuthorize: true, // 微信登录仅请求授权认证
					success: (event) => {
						req(event.code);
					},
					fail: function (err) {
						console.log(err);
					}
				});
			});
		},
		async login(pid) {
			let code = await this.login1();
			const data = await commonloginwxLogin({
				code: code
				// pid: pid
			});
			uni.setStorageSync('token', data.data.token);
			uni.setStorageSync('userid', data.data.id);
            if(flag){
                this.flag2couponFun(flag)
            }
			this.$isResolve();
		}
	},

	onHide: function () {
		console.log('App Hide');
	}
};
</script>

<style lang="scss">
@import '@/uni_modules/uview-ui/index.scss';
image {
	display: block;
	flex-shrink: 0;
}
.block {
	display: block;
}
.shrink {
	flex-shrink: 0;
}
.center {
	display: flex;
	justify-content: center;
	align-items: center;
}
.between {
	display: flex;
	align-items: center;
	justify-content: space-between;
}
.column {
	display: flex;
	flex-direction: column;
}
.flex {
	display: flex;
	align-items: center;
}
.flex1 {
	display: flex;
}
.between1 {
	display: flex;
	justify-content: space-between;
}
.wrap {
	flex-wrap: wrap;
}
.readonly1 {
	pointer-events: none;
}
// @font-face {
// 	font-family: 'HEAVY';
// 	src: url('https://coffee.a.hlidc.cn/uploads/font/NeverMind-Heavy.ttf') format('truetype');
// }
// @font-face {
// 	font-family: 'regular';
// 	src: url('https://coffee.a.hlidc.cn/uploads/font/NeverMind-Regular.ttf') format('truetype');
// }
</style>
